<%--
  Created by IntelliJ IDEA.
  User: legion
  Date: 2020/12/21
  Time: 16:37
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!--实现采购管理的增删查改-->
<html>
<head>
    <title>Title</title>
    <link href="../css/bootstrap.min.css" rel="stylesheet">
    <script type="text/javascript" src="../js/jquery-3.3.1.min.js"></script>
    <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
    <script src="../js/bootstrap.min.js"></script>
</head>
<style type="text/css">
    .div
    {
        display:none;
        border:1px solid ;
        height:50%;
        width:30%;
        position:absolute;/*让节点脱离文档流,我的理解就是,从页面上浮出来,不再按照文档其它内容布局*/
        top:24%;/*节点脱离了文档流,如果设置位置需要用top和left,right,bottom定位*/
        left:24%;
        z-index:2;/*个人理解为层级关系,由于这个节点要在顶部显示,所以这个值比其余节点的都大*/
        background: white;
    }
    .over
    {
        width: 100%;
        height: 100%;
        opacity:0.3;/*设置背景色透明度,1为完全不透明,IE需要使用filter:alpha(opacity=80);*/
        filter:alpha(opacity=80);
        display: none;
        position:absolute;
        top:0;
        left:0;
        z-index:1;
        background-color: rgb(0,0,0);
    }
</style>
<script>
    /**
     * 实现采购管理的添加
     */
    //根据供应商id查询供应商电话
    //onchang()事件 选择供货商自动选择供货商电话
    function fun(gid){
        $.ajax({
            url:"http://localhost:8080/purchaseServlet",
            type:"post",
            data:{type:3,'gid':gid},
            success:function (data,status,xhr) {
                 if(data==""){
                     return;
                 }
                 data = JSON.parse(data);
                $("#supplierPhone").empty()
                 for(var a=0;a<data.length;a++){
                     $("#supplierPhone").val(data[a].phone)
                 }
            }
        })
    }
    $(function () {
        //点击按钮显示添加div 并查询显示所有供应商的名字
         $("#insert").click(function () {
                $("#insertDiv").show()
             $.ajax({
                 url:"http://localhost:8080/purchaseServlet",
                 type:"post",
                 data:{type:2},
                 success: function (data,status,xhr) {
                     if(data==""){
                         return;
                     }
                    data = JSON.parse(data);
                     $("#supplierName1").empty();
                    var supplierName1="<option>请选择一个供应商</option>";
                    for(var a=0;a<data.length;a++){
                        supplierName1+="<option value='"+data[a].gid+"'>"+data[a].name+"</option>"
                    }
                    $("#supplierName1").html(supplierName1);
                 }
             })
         })
        /**
         *点击按钮关闭div
         */
        $("#close").click(function () {
            $("#insertDiv").hide()
        })
        //根据供货商名称模糊查询供货商
        $("#selectSupplierName1").click(function () {
                $.ajax({
                    url:"http://localhost:8080/purchaseServlet",
                    type:"post",
                    data:{type:4,'supplierName':$("#selectSupplierName").val()},
                    success:function (data,status,xhr) {
                          if(data==""){
                              return;
                          }
                          data = JSON.parse(data);
                          $("#supplierName1").empty();
                          var supplierName1="<option>请选择一个供应商</option>";
                          for(var a=0;a<data.length;a++){
                              supplierName1+="<option value='"+data[a].gid+"'>"+data[a].name+"</option>"
                          }
                          $("#supplierName1").html(supplierName1);
                    }
                })
        })
        //点击提交 获取所有文本框的值
        $("#submit1").click(function () {
            if ($("#commodityName1").val()=="" || $("#cas1").val()=="" || $("#amount").val()=="" || $("#price").val()=="" || $("#supplierName1").val()=="" || $("#priceStatus option:selected").text()=="请选择是否含税"){
                alert("请补全采购信息！")
                return;
            }
             $.ajax({
                 url:"http://localhost:8080/purchaseServlet",
                 type:"post",
                 data:{type:1,'commodityName':$("#commodityName1").val(),
                       'cas':$("#cas1").val(),'amount':$("#amount").val(),
                       'price':$("#price").val(),'priceStatus':$("#priceStatus option:selected").val(),
                       'supplierName':$("#supplierName1 option:selected").text(),'supplierPhone':$("#supplierPhone").val()
                 },
                 success:function (data,status,xhr) {
                     $("#commodityName1").val('')
                     $("#cas1").val('')
                     $("#amount").val('')
                     $("#price").val('')
                     $("#supplierPhone").val('')
                     $("#supplierName1").empty();
                     var priceStatus1 ="<option>请选择是否含税</option><option value='0'>含税</option> <option value='1'>不含税</option>"
                     $("#priceStatus").html(priceStatus1)

                     $("#insertDiv").hide()
                     //添加后重新查询数据
                     $.ajax({
                         url:"http://localhost:8080/purchaseServlet",
                         type:"post",
                         data:{type:5},
                         success:function (data,status,xhr) {
                             if(data==""){
                                 return;
                             }
                             data = JSON.parse(data);
                             $("#tbody").empty();
                             var tr = "";
                             for(var a=0;a<data.length;a++){
                                 //判断是否含税
                                 var tax="";
                                 if(data[a].price_status=="0"){
                                     tax="含税";
                                 }else{
                                     tax="不含税";
                                 }

                                 if(data[a].tracking_number==""){
                                     tr+="<tr><td><input type='radio' name='radio' value='"+data[a].cid+"'></td><td>"+data[a].aid+"</td><td>"+data[a].user_name+"</td>" +
                                         "<td>"+data[a].name+"</td><td>"+data[a].cas+"</td><td>"+data[a].amount+"</td><td>"+data[a].price+"</td>" +
                                         "<td>"+tax+"</td><td>"+data[a].sum_price+"</td><td>"+data[a].supplier_name+"</td>" +
                                         "<td>"+data[a].supplier_phone+"</td><td>"+data[a].tracking_number+"</td><td>"+data[a].create_time+"</td>" +
                                         "<td>"+data[a].ann+"</td><td><button onclick='x("+data[a].cid+")'>添加物流单号</button></td></tr>"
                                 }else{
                                     tr+="<tr><td><input type='radio' name='radio' value='"+data[a].cid+"'></td><td>"+data[a].aid+"</td><td>"+data[a].user_name+"</td>" +
                                         "<td>"+data[a].name+"</td><td>"+data[a].cas+"</td><td>"+data[a].amount+"</td><td>"+data[a].price+"</td>" +
                                         "<td>"+tax+"</td><td>"+data[a].sum_price+"</td><td>"+data[a].supplier_name+"</td>" +
                                         "<td>"+data[a].supplier_phone+"</td><td>"+data[a].tracking_number+"</td><td>"+data[a].create_time+"</td>" +
                                         "<td>"+data[a].ann+"</td></tr>"
                                 }
                             }
                             $("#tbody").append(tr)
                         }
                     })
                     //添加后刷新按钮组
                     $.ajax({
                         url:"http://localhost:8080/purchaseServlet",
                         type:"post",
                         data:{type:10},
                         success: function (data,status,xhr) {
                             console.log(data)
                             if(data==""){
                                 return;
                             }
                             data = JSON.parse(data)
                             $("#lineDiv").empty()
                             let button = ""
                             for (let i = 1; i <= data.page; i++) {
                                 button+="<button onclick='page("+i+")' value='"+i+"' class=\"btn btn-primary\">"+i+"</button>"
                             }
                             $("#lineDiv").append(button)
                         }
                     })
                 }
             })

    })
        /**
         * 点击按钮重置文本框的值
         */
        $("#reset").click(function () {
            $("#selectSupplierName").val('')
            $("#commodityName1").val('')
            $("#cas1").val('')
            $("#amount").val('')
            $("#price").val('')
            $("#supplierPhone").val('')
            var priceStatus1 ="<option>请选择是否含税</option><option value='0'>含税</option> <option value='1'>不含税</option>"
            $("#priceStatus").html(priceStatus1)
            $.ajax({
                url:"http://localhost:8080/purchaseServlet",
                type:"post",
                data:{type:2},
                success: function (data,status,xhr) {
                    if(data==""){
                        return;
                    }
                    data = JSON.parse(data);
                    $("#supplierName1").empty();
                    var supplierName1="<option>请选择一个供应商</option>";
                    for(var a=0;a<data.length;a++){
                        supplierName1+="<option value='"+data[a].gid+"'>"+data[a].name+"</option>"
                    }
                    $("#supplierName1").html(supplierName1);
                }
            })
        })
    })
    /**
     * 实现采购管理的查询
     */
    //点击分页按钮查询数据
    function page(i){
        $.ajax({
            url:"http://localhost:8080/purchaseServlet",
            type:"post",
            data:{type:11,page:i,'commodityName':$("#commodityName").val(),
                'cas':$("#cas").val(),'supplierName':$("#supplierName").val(),
                'trackingNumber':$("#trackingNumber").val()},
            success: function (data,status,xhr) {
                    if(data==""){
                        return;
                    }
                    data = JSON.parse(data)
                    $("#tbody").empty()
                    let tr = ""
                for(let a=0;a<data.length;a++){
                    //判断是否含税
                    let tax="";
                    if(data[a].price_status=="0"){
                        tax="含税";
                    }else{
                        tax="不含税";
                    }

                    if(data[a].tracking_number==""){
                        tr+="<tr><td><input type='radio' name='radio' value='"+data[a].cid+"'></td><td>"+data[a].aid+"</td><td>"+data[a].user_name+"</td>" +
                            "<td>"+data[a].name+"</td><td>"+data[a].cas+"</td><td>"+data[a].amount+"</td><td>"+data[a].price+"</td>" +
                            "<td>"+tax+"</td><td>"+data[a].sum_price+"</td><td>"+data[a].supplier_name+"</td>" +
                            "<td>"+data[a].supplier_phone+"</td><td>"+data[a].tracking_number+"</td><td>"+data[a].create_time+"</td>" +
                            "<td>"+data[a].ann+"</td><td><button onclick='x("+data[a].cid+")'>添加物流单号</button></td></tr>"
                    }else{
                        tr+="<tr><td><input type='radio' name='radio' value='"+data[a].cid+"'></td><td>"+data[a].aid+"</td><td>"+data[a].user_name+"</td>" +
                            "<td>"+data[a].name+"</td><td>"+data[a].cas+"</td><td>"+data[a].amount+"</td><td>"+data[a].price+"</td>" +
                            "<td>"+tax+"</td><td>"+data[a].sum_price+"</td><td>"+data[a].supplier_name+"</td>" +
                            "<td>"+data[a].supplier_phone+"</td><td>"+data[a].tracking_number+"</td><td>"+data[a].create_time+"</td>" +
                            "<td>"+data[a].ann+"</td></tr>"
                    }
                }
                $("#tbody").append(tr)
            }
        })
    }
    /**
     *
     * 点击按钮添加物流单号
     */
    function x(cid){
        $("#div1").show()
        $("#submit").click(function () {
            $.ajax({
                url:"http://localhost:8080/purchaseServlet",
                type:"post",
                data:{type:12,id:cid,number:$("#number").val()},
                success: function (data,status,xhr) {
                    $("#div1").hide()
                    $.ajax({
                        url:"http://localhost:8080/purchaseServlet",
                        type:"post",
                        data:{type:5},
                        success:function (data,status,xhr) {
                            if(data==""){
                                return;
                            }
                            data = JSON.parse(data);
                            $("#tbody").empty();
                            var tr = "";
                            for(var a=0;a<data.length;a++){
                                //判断是否含税
                                var tax="";
                                if(data[a].price_status=="0"){
                                    tax="含税";
                                }else{
                                    tax="不含税";
                                }
                                if(data[a].tracking_number==""){
                                    tr+="<tr><td><input type='radio' name='radio' value='"+data[a].cid+"'></td><td>"+data[a].aid+"</td><td>"+data[a].user_name+"</td>" +
                                        "<td>"+data[a].name+"</td><td>"+data[a].cas+"</td><td>"+data[a].amount+"</td><td>"+data[a].price+"</td>" +
                                        "<td>"+tax+"</td><td>"+data[a].sum_price+"</td><td>"+data[a].supplier_name+"</td>" +
                                        "<td>"+data[a].supplier_phone+"</td><td>"+data[a].tracking_number+"</td><td>"+data[a].create_time+"</td>" +
                                        "<td>"+data[a].ann+"</td><td><button onclick='x("+data[a].cid+")'>添加物流单号</button></td></tr>"
                                }else{
                                    tr+="<tr><td><input type='radio' name='radio' value='"+data[a].cid+"'></td><td>"+data[a].aid+"</td><td>"+data[a].user_name+"</td>" +
                                        "<td>"+data[a].name+"</td><td>"+data[a].cas+"</td><td>"+data[a].amount+"</td><td>"+data[a].price+"</td>" +
                                        "<td>"+tax+"</td><td>"+data[a].sum_price+"</td><td>"+data[a].supplier_name+"</td>" +
                                        "<td>"+data[a].supplier_phone+"</td><td>"+data[a].tracking_number+"</td><td>"+data[a].create_time+"</td>" +
                                        "<td>"+data[a].ann+"</td></tr>"
                                }

                            }
                            $("#tbody").append(tr)
                        }
                    })
                }
            })
        })
    }
    $(function () {


        /**
         * 分页 添加分页按钮
         */
         $.ajax({
             url:"http://localhost:8080/purchaseServlet",
             type:"post",
             data:{type:10,'commodityName':$("#commodityName").val(),
                 'cas':$("#cas").val(),'supplierName':$("#supplierName").val(),
                 'trackingNumber':$("#trackingNumber").val()},
             success: function (data,status,xhr) {
                    console.log(data)
                    if(data==""){
                        return;
                    }
                       data = JSON.parse(data)
                       $("#lineDiv").empty()
                       let button = ""
                 for (let i = 1; i <= data.page; i++) {
                       button+="<button onclick='page("+i+")' value='"+i+"' class=\"btn btn-primary\">"+i+"</button>"
                 }
                       $("#lineDiv").append(button)
             }
         })
        /**
         * 查询全部数据
         */
         $.ajax({
             url:"http://localhost:8080/purchaseServlet",
             type:"post",
             data:{type:5},
             success:function (data,status,xhr) {
                  if(data==""){
                      return;
                  }
                  data = JSON.parse(data);
                  $("#tbody").empty();
                  var tr = "";
                  for(var a=0;a<data.length;a++){
                      //判断是否含税
                      var tax="";
                      if(data[a].price_status=="0"){
                         tax="含税";
                      }else{
                          tax="不含税";
                      }
                      if(data[a].tracking_number==""){
                          tr+="<tr><td><input type='radio' name='radio' value='"+data[a].cid+"'></td><td>"+data[a].aid+"</td><td>"+data[a].user_name+"</td>" +
                              "<td>"+data[a].name+"</td><td>"+data[a].cas+"</td><td>"+data[a].amount+"</td><td>"+data[a].price+"</td>" +
                              "<td>"+tax+"</td><td>"+data[a].sum_price+"</td><td>"+data[a].supplier_name+"</td>" +
                              "<td>"+data[a].supplier_phone+"</td><td>"+data[a].tracking_number+"</td><td>"+data[a].create_time+"</td>" +
                              "<td>"+data[a].ann+"</td><td><button onclick='x("+data[a].cid+")'>添加物流单号</button></td></tr>"
                      }else{
                          tr+="<tr><td><input type='radio' name='radio' value='"+data[a].cid+"'></td><td>"+data[a].aid+"</td><td>"+data[a].user_name+"</td>" +
                              "<td>"+data[a].name+"</td><td>"+data[a].cas+"</td><td>"+data[a].amount+"</td><td>"+data[a].price+"</td>" +
                              "<td>"+tax+"</td><td>"+data[a].sum_price+"</td><td>"+data[a].supplier_name+"</td>" +
                              "<td>"+data[a].supplier_phone+"</td><td>"+data[a].tracking_number+"</td><td>"+data[a].create_time+"</td>" +
                              "<td>"+data[a].ann+"</td></tr>"
                      }

                  }
                  $("#tbody").append(tr)
             }
         })
        /**
         * 根据条件模糊查询数据
         */
        $("#select").click(function () {
            $.ajax({
                url:"http://localhost:8080/purchaseServlet",
                type:"post",
                data:{type:6,'commodityName':$("#commodityName").val(),
                    'cas':$("#cas").val(),'supplierName':$("#supplierName").val(),
                    'trackingNumber':$("#trackingNumber").val()},
                success:function (data,status,xhr) {
                    if(data==""){
                        return;
                    }
                    data = JSON.parse(data);
                    $("#tbody").empty();
                    var tr = "";
                    for(var a=0;a<data.length;a++){
                        //判断是否含税
                        var tax="";
                        if(data[a].price_status=="0"){
                            tax="含税";
                        }else{
                            tax="不含税";
                        }

                        if(data[a].tracking_number==""){
                            tr+="<tr><td><input type='radio' name='radio' value='"+data[a].cid+"'></td><td>"+data[a].aid+"</td><td>"+data[a].user_name+"</td>" +
                                "<td>"+data[a].name+"</td><td>"+data[a].cas+"</td><td>"+data[a].amount+"</td><td>"+data[a].price+"</td>" +
                                "<td>"+tax+"</td><td>"+data[a].sum_price+"</td><td>"+data[a].supplier_name+"</td>" +
                                "<td>"+data[a].supplier_phone+"</td><td>"+data[a].tracking_number+"</td><td>"+data[a].create_time+"</td>" +
                                "<td>"+data[a].ann+"</td><td><button onclick='x("+data[a].cid+")'>添加物流单号</button></td></tr>"
                        }else{
                            tr+="<tr><td><input type='radio' name='radio' value='"+data[a].cid+"'></td><td>"+data[a].aid+"</td><td>"+data[a].user_name+"</td>" +
                                "<td>"+data[a].name+"</td><td>"+data[a].cas+"</td><td>"+data[a].amount+"</td><td>"+data[a].price+"</td>" +
                                "<td>"+tax+"</td><td>"+data[a].sum_price+"</td><td>"+data[a].supplier_name+"</td>" +
                                "<td>"+data[a].supplier_phone+"</td><td>"+data[a].tracking_number+"</td><td>"+data[a].create_time+"</td>" +
                                "<td>"+data[a].ann+"</td></tr>"
                        }
                    }
                    $("#tbody").append(tr)
                    //刷新按钮组
                    $.ajax({
                        url:"http://localhost:8080/purchaseServlet",
                        type:"post",
                        data:{type:10,'commodityName':$("#commodityName").val(),
                            'cas':$("#cas").val(),'supplierName':$("#supplierName").val(),
                            'trackingNumber':$("#trackingNumber").val()},
                        success: function (data,status,xhr) {
                            console.log(data)
                            if(data==""){
                                return;
                            }
                            data = JSON.parse(data)
                            $("#lineDiv").empty()
                            let button = ""
                            for (let i = 1; i <= data.page; i++) {
                                button+="<button onclick='page("+i+")' value='"+i+"' class=\"btn btn-primary\">"+i+"</button>"
                            }
                            $("#lineDiv").append(button)
                        }
                    })
                }
            })
        })
    })
    /**
     * 采购管理中的删除
     */
    $(function () {
         $("#delete").click(function () {
             var radioValue= $("input[name='radio']:checked").val();//获取当前单选按钮value值
             if(radioValue==undefined){
                 alert("请选中一行")
                 return;
             }
             $.ajax({
                 url:"http://localhost:8080/purchaseServlet",
                 type:"post",
                 data:{type:7,'radioValue':radioValue},
                 success:function (data,status,xhr) {
                        alert("删除一条数据")

                 }
             })
             //删除后重新查询数据
             $.ajax({
                 url:"http://localhost:8080/purchaseServlet",
                 type:"post",
                 data:{type:5},
                 success:function (data,status,xhr) {
                     if(data==""){
                         return;
                     }
                     data = JSON.parse(data);
                     $("#tbody").empty();
                     var tr = "";
                     for(var a=0;a<data.length;a++){
                         //判断是否含税
                         var tax="";
                         if(data[a].price_status=="0"){
                             tax="含税";
                         }else{
                             tax="不含税";
                         }

                         if(data[a].tracking_number==""){
                             tr+="<tr><td><input type='radio' name='radio' value='"+data[a].cid+"'></td><td>"+data[a].aid+"</td><td>"+data[a].user_name+"</td>" +
                                 "<td>"+data[a].name+"</td><td>"+data[a].cas+"</td><td>"+data[a].amount+"</td><td>"+data[a].price+"</td>" +
                                 "<td>"+tax+"</td><td>"+data[a].sum_price+"</td><td>"+data[a].supplier_name+"</td>" +
                                 "<td>"+data[a].supplier_phone+"</td><td>"+data[a].tracking_number+"</td><td>"+data[a].create_time+"</td>" +
                                 "<td>"+data[a].ann+"</td><td><button onclick='x("+data[a].cid+")'>添加物流单号</button></td></tr>"
                         }else{
                             tr+="<tr><td><input type='radio' name='radio' value='"+data[a].cid+"'></td><td>"+data[a].aid+"</td><td>"+data[a].user_name+"</td>" +
                                 "<td>"+data[a].name+"</td><td>"+data[a].cas+"</td><td>"+data[a].amount+"</td><td>"+data[a].price+"</td>" +
                                 "<td>"+tax+"</td><td>"+data[a].sum_price+"</td><td>"+data[a].supplier_name+"</td>" +
                                 "<td>"+data[a].supplier_phone+"</td><td>"+data[a].tracking_number+"</td><td>"+data[a].create_time+"</td>" +
                                 "<td>"+data[a].ann+"</td></tr>"
                         }
                     }
                     $("#tbody").append(tr)
                 }
             })
             //删除后刷新按钮组
             $.ajax({
                 url:"http://localhost:8080/purchaseServlet",
                 type:"post",
                 data:{type:10,'commodityName':$("#commodityName").val(),
                     'cas':$("#cas").val(),'supplierName':$("#supplierName").val(),
                     'trackingNumber':$("#trackingNumber").val()},
                 success: function (data,status,xhr) {
                     console.log(data)
                     if(data==""){
                         return;
                     }
                     data = JSON.parse(data)
                     $("#lineDiv").empty()
                     let button = ""
                     for (let i = 1; i <= data.page; i++) {
                         button+="<button onclick='page("+i+")' value='"+i+"' class=\"btn btn-primary\">"+i+"</button>"
                     }
                     $("#lineDiv").append(button)
                 }
             })
         })
        $("#close1").click(function () {
                $("#updateDiv").hide()
        })

    })


    /**
     * 实现采购管理中的修改
     */
    //根据供应商id查询供应商电话
    //onchang()事件 选择供货商自动选择供货商电话
    function fun1(gid){
        $.ajax({
            url:"http://localhost:8080/purchaseServlet",
            type:"post",
            data:{type:3,'gid':gid},
            success:function (data,status,xhr) {
                if(data==""){
                    return;
                }
                data = JSON.parse(data);
                $("#updateSupplierPhone").empty()
                for(var a=0;a<data.length;a++){
                    $("#updateSupplierPhone").val(data[a].phone)
                }
            }
        })
    }
    $(function () {
        $("#update").click(function () {
            var radioValue= $("input[name='radio']:checked").val();//获取当前单选按钮value值
            if(radioValue==undefined){
                alert("请选中一行")
                return;
            }
           $("#updateDiv").show()
            $.ajax({
                url:"http://localhost:8080/purchaseServlet",
                type:"post",
                data:{type:8,'cid':radioValue},
                success:function (data,status,xhr) {
                      if(data==""){
                          return;
                      }
                      data=JSON.parse(data)
                      $("#updateCommodityName").val(data.name);
                      $("#updateCas").val(data.cas);
                      $("#updateAmount").val(data.amount);
                      $("#updatePrice").val(data.price)
                      $("#updatePriceStatus").val(data.price_status)
                      var supplierName = ""
                      supplierName+="<option>"+data.supplier_name+"</option>"
                      $("#updateSupplierName2").html(supplierName)
                      $("#updateSupplierPhone").val(data.supplier_phone);
                }
            })
        })
        //根据供货商名称模糊查询供货商
        $("#updateSupplierName1").click(function () {
            $.ajax({
                url:"http://localhost:8080/purchaseServlet",
                type:"post",
                data:{type:4,'supplierName':$("#updateSupplierName").val()},
                success:function (data,status,xhr) {
                    if(data==""){
                        return;
                    }
                    data = JSON.parse(data);
                    $("#updateSupplierName2").empty();
                    var supplierName1="<option>请选择一个供应商</option>";
                    for(var a=0;a<data.length;a++){
                        supplierName1+="<option value='"+data[a].gid+"'>"+data[a].name+"</option>"
                    }
                    $("#updateSupplierName2").html(supplierName1);
                    $("#updateSupplierPhone").val(data.phone);
                }
            })
        })
        /**
         *点击按钮获的文本框全部数据  到数据库修改数据
         */
        $("#updateSubmit").click(function () {
            var radioValue= $("input[name='radio']:checked").val();//获取当前单选按钮value值
              $.ajax({
                  url:"http://localhost:8080/purchaseServlet",
                  type:"post",
                  data:{type:9,'CommodityName':$("#updateCommodityName").val(),
                        'cas':$("#updateCas").val(),'amount':$("#updateAmount").val(),
                        'price':$("#updatePrice").val(),'priceStatus':$("#updatePriceStatus option:selected").val(),
                        'supplierName':$("#updateSupplierName2 option:selected").text(),
                        'supplierPhone':$("#updateSupplierPhone").val(),'cid':radioValue
                  },
                  success:function (data,status,xhr) {
                      //修改后重新查询数据
                      $.ajax({
                          url:"http://localhost:8080/purchaseServlet",
                          type:"post",
                          data:{type:5},
                          success:function (data,status,xhr) {
                              if(data==""){
                                  return;
                              }
                              data = JSON.parse(data);
                              $("#tbody").empty();
                              var tr = "";
                              for(var a=0;a<data.length;a++){
                                  //判断是否含税
                                  var tax="";
                                  if(data[a].price_status=="0"){
                                      tax="含税";
                                  }else{
                                      tax="不含税";
                                  }

                                  if(data[a].tracking_number==""){
                                      tr+="<tr><td><input type='radio' name='radio' value='"+data[a].cid+"'></td><td>"+data[a].aid+"</td><td>"+data[a].user_name+"</td>" +
                                          "<td>"+data[a].name+"</td><td>"+data[a].cas+"</td><td>"+data[a].amount+"</td><td>"+data[a].price+"</td>" +
                                          "<td>"+tax+"</td><td>"+data[a].sum_price+"</td><td>"+data[a].supplier_name+"</td>" +
                                          "<td>"+data[a].supplier_phone+"</td><td>"+data[a].tracking_number+"</td><td>"+data[a].create_time+"</td>" +
                                          "<td>"+data[a].ann+"</td><td><button onclick='x("+data[a].cid+")'>添加物流单号</button></td></tr>"
                                  }else{
                                      tr+="<tr><td><input type='radio' name='radio' value='"+data[a].cid+"'></td><td>"+data[a].aid+"</td><td>"+data[a].user_name+"</td>" +
                                          "<td>"+data[a].name+"</td><td>"+data[a].cas+"</td><td>"+data[a].amount+"</td><td>"+data[a].price+"</td>" +
                                          "<td>"+tax+"</td><td>"+data[a].sum_price+"</td><td>"+data[a].supplier_name+"</td>" +
                                          "<td>"+data[a].supplier_phone+"</td><td>"+data[a].tracking_number+"</td><td>"+data[a].create_time+"</td>" +
                                          "<td>"+data[a].ann+"</td></tr>"
                                  }
                              }
                              $("#tbody").append(tr)
                          }
                      })
                      //修改后刷新按钮组
                      $.ajax({
                          url:"http://localhost:8080/purchaseServlet",
                          type:"post",
                          data:{type:10,'commodityName':$("#commodityName").val(),
                              'cas':$("#cas").val(),'supplierName':$("#supplierName").val(),
                              'trackingNumber':$("#trackingNumber").val()},
                          success: function (data,status,xhr) {
                              console.log(data)
                              if(data==""){
                                  return;
                              }
                              data = JSON.parse(data)
                              $("#lineDiv").empty()
                              let button = ""
                              for (let i = 1; i <= data.page; i++) {
                                  button+="<button onclick='page("+i+")' value='"+i+"' class=\"btn btn-primary\">"+i+"</button>"
                              }
                              $("#lineDiv").append(button)
                          }
                      })
                        $("#updateDiv").hide()
                  }
              })
        })
        /**
         * 点击按钮重置文本框的值
         */
        $("#updateReset").click(function () {
            $("#updateSupplierName").val('')
            $("#updateCommodityName").val('')
            $("#updateCas").val('')
            $("#updateAmount").val('')
            $("#updatePrice").val('')
            $("#updateSupplierPhone").val('')
            var priceStatus1 ="<option>请选择是否含税</option><option value='0'>含税</option> <option value='1'>不含税</option>"
            $("#updatePriceStatus").html(priceStatus1)
            $.ajax({
                url:"http://localhost:8080/purchaseServlet",
                type:"post",
                data:{type:2},
                success: function (data,status,xhr) {
                    if(data==""){
                        return;
                    }
                    data = JSON.parse(data);
                    $("#updateSupplierName2").empty();
                    var supplierName1="<option>请选择一个供应商</option>";
                    for(var a=0;a<data.length;a++){
                        supplierName1+="<option value='"+data[a].gid+"'>"+data[a].name+"</option>"
                    }
                    $("#updateSupplierName2").html(supplierName1);
                }
            })
        })
    })

</script>
<body>
<center>
    <h1>采购管理</h1>
    <div>
        商品名：<input id="commodityName"> Cas号：<input id="cas"> 供应商名称：<input id="supplierName"> 物流单号：<input id="trackingNumber">
        <button id="select" class="btn btn-primary">查询</button>
    </div>
    <br/>
    <div>
        <button id="insert" class="btn btn-primary">添加</button> <button id="update" class="btn btn-primary">修改</button> <button id="delete" class="btn btn-primary">删除</button>
    </div>
    <table id="table" class="table table-bordered">
        <tr id="tr" class="table-active">
            <td></td>
            <td>编号</td>
            <td>业务员</td>
            <td>产品名称</td>
            <td>cas号</td>
            <td>数量</td>
            <td>单价</td>
            <td>是否含税</td>
            <td>总价</td>
            <td>供应商名称</td>
            <td>供应商电话</td>
            <td>物流单号</td>
            <td>创建日期</td>
            <td>发票</td>
            <td>操作</td>
        </tr>
        <tbody id="tbody">

        </tbody>
    </table>
    <!--按钮组-->
    <div id="lineDiv">

    </div>
</center>
<!--添加的div-->
<div id="insertDiv" class="div" style="height: 65vh;overflow-y: scroll">
    <table>
        <tr><td>供应商名称：</td> <td><input id="selectSupplierName"></td> <td><button id="selectSupplierName1" class="btn btn-primary">查询</button></td></tr>
        <tr><td>商品名称：</td> <td colspan="2"><input id="commodityName1"></td></tr>
        <tr><td>Cas号：</td> <td colspan="2"><input id="cas1"></td></tr>
        <tr><td>数量：</td> <td colspan="2"><input id="amount"></td></tr>
        <tr><td>单价：</td> <td><input id="price"></td>
            <td>
                <select id="priceStatus">
                    <option>请选择是否含税</option>
                    <option value="0">含税</option>
                    <option value="1">不含税</option>
                </select>
            </td>
        </tr>
        <tr><td>供应商名称：</td> <td colspan="2"><select id="supplierName1" style="width: 200px" onchange="fun(this.value)"></select></td></tr>
        <tr><td>联系电话：</td> <td colspan="2"><input id="supplierPhone"></td></tr>
        <tr><td colspan="3"><input id="submit1" type="button" value="提交"> <input type="button" id="reset" value="重置"></td> <td><input type="button" id="close" value="关闭"></td></tr>
    </table>
</div>

<!--修改的div-->
<div id="updateDiv" class="div" style="height: 65vh;overflow-y: scroll">
    <table>
        <tr><td>供应商名称：</td> <td><input id="updateSupplierName"></td> <td><button id="updateSupplierName1" class="btn btn-primary">查询</button></td></tr>
        <tr><td>商品名称：</td> <td colspan="2"><input id="updateCommodityName"></td></tr>
        <tr><td>Cas号：</td> <td colspan="2"><input id="updateCas"></td></tr>
        <tr><td>数量：</td> <td colspan="2"><input id="updateAmount"></td></tr>
        <tr><td>单价：</td> <td><input id="updatePrice"></td>
            <td>
                <select id="updatePriceStatus">
                    <option>请选择是否含税</option>
                    <option value="0">含税</option>
                    <option value="1">不含税</option>
                </select>
            </td>
        </tr>
        <tr><td>供应商名称：</td> <td colspan="2"><select id="updateSupplierName2" style="width: 200px" onchange="fun1(this.value)"></select></td></tr>
        <tr><td>联系电话：</td> <td colspan="2"><input id="updateSupplierPhone"></td></tr>
        <tr><td colspan="3"><input id="updateSubmit" type="button" value="提交"> <input type="button" id="updateReset" value="重置"> <input type="button" id="close1" value="关闭"></td> </tr>
    </table>
</div>
<!--添加物流单号-->
<div id="div1" class="div">
    物流单号：<input id="number">
    <button id="submit">提交</button><button id="close2">关闭</button>
</div>
</body>
</html>
